<? 
session_start();
if(!session_is_registered(uid)){
    echo "You have to login to view this page!</br></br>";
    echo "Click here to return to the "; 
    echo '<a href="./../index.php" title="Login">Login Page</a></br></br>';
    echo "Or sign up using this link ";
    echo '<a href="./../Registration/registration.html" title="Registration">Registration Page</a>';
exit();
}

else

    //Manual SQL Connection
    $con = mysql_connect("localhost", "root", "root") or die ( "Error connectiong to DB: ".mysql_error());
       
    mysql_select_db("reeferslog", $con) or die ( "Error selecting specific DB, reefeerslog: ".mysql_error());

if ($_GET['action'] == 'edit') {
    
    $qry = "SELECT * FROM l_hardware where user_id='". $_SESSION['uid'] ."' and id='".$_GET['id']."'";
    
    $results = mysql_query($qry)or die(mysql_error($con));

    extract(mysql_fetch_assoc($results));
    
}else {
    //set values blanks
    $hmanufacturer = '';
    $notes = '';
    $qty = 0;
    $cost = 0;
    $lname = '';
    $hardware_type = '';
    
    //Function to make a valid date input
    $datepurchased = $year."-".$month."-".$day;
    
    //Date variables
    $day = 0;
    $month = 0;
    $year = 0;

    list($year, $month, $day) = explode("-", $datepurchased);
}

?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="http://localhost/ReefersLogApp/CSS/Generalpagelayout.css" />
    
    <script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/jquery.ba-hashchange.min.js'></script>
    <script type='text/javascript' src='./../scripts/js/dynamicpage.js'></script>
    
    <title><?php echo ucfirst($_GET['action']); ?>Hardware</title>
</head>
<div id="container">
	<div id="header">
            <h1>
		Reefers Log
            </h1>
	</div>
	<div id="navigation">
		<ul>
			<li><a href="./../WelcomePage/WelcomePage.php">Home</a></li>
			<li><a href="./../Profile/userprofile.php">Profile</a></li>
			<li><a href="./../Tools/tools.php">Tools</a></li>
			<li><a href="./../Logout/logout.php">Logout</a></li>
		</ul>
	</div>
	<div id="content-container">
		<div id="section-navigation">
                    <object id="loader" name="frameloader" type="text/html" data="http://localhost/ReefersLogApp/Welcome/WelcomePage.php/"></object>
			<ul>
                           
				<li><a href="viewtank.php">View Tank</a></li>				
                                <li><a href="./../Test_Logs/watertest.html">Water Tests</a></li>
				<li><a href="./../Equipment/equip.html">Equipment</a></li>
			</ul>
		</div>
		<div id="content">
                    <h2>
                        Your Aquarium Statistics:
                    </h2>
                    <p>
                        Edit lighting hardware information using this page. 
                    </p>

    <form action="commitedit.php?action=<?php echo $_GET['action']?>&type=hardware&id=<? echo $_GET['id']?>" method="post">

                    <table align="center" border="1">
                        <thead>
                        <th>Lighting Hardware</th>
                        <th>
                             <label> Date Purchased (MM/DD/YYYY):</br><select name="month" required="required" value="">
                                     <option value="" SELECTED>
                                            <?php 
                                            $m = mysql_query("select id, datepurchased from l_hardware where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by datepurchased desc");
                                            while($row = mysql_fetch_array($m)){
                                               $selected = " SELECTED";
                                               if ( $row['datepurchased'] == $datepurchased){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $datepurchased);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$month.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                    </select><select name="day" required="required">
                                        <option value="" SELECTED>
                                            <?php 
                                            $d = mysql_query("select id, datepurchased from l_hardware where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by datepurchased desc");
                                            while($row = mysql_fetch_array($d)){
                                               $selected = " SELECTED";
                                               if ( $row['datepurchased'] == $datepurchased){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $datepurchased);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$day.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>01</option>
                                        <option>02</option>
                                        <option>03</option>
                                        <option>04</option>
                                        <option>05</option>
                                        <option>06</option>
                                        <option>07</option>
                                        <option>08</option>
                                        <option>09</option>
                                        <option>10</option>
                                        <option>11</option>
                                        <option>12</option>
                                        <option>13</option>
                                        <option>14</option>
                                        <option>15</option>
                                        <option>16</option>
                                        <option>17</option>
                                        <option>18</option>
                                        <option>19</option>
                                        <option>20</option>
                                        <option>21</option>
                                        <option>22</option>
                                        <option>23</option>
                                        <option>24</option>
                                        <option>25</option>
                                        <option>26</option>
                                        <option>27</option>
                                        <option>28</option>
                                        <option>29</option>
                                        <option>30</option>
                                        <option>31</option>
                                    </select><select name="year" required="required">
                                        <option value="" SELECTED>
                                            <?php 
                                            $y = mysql_query("select id, datepurchased from l_hardware where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by datepurchased desc");
                                            while($row = mysql_fetch_array($y)){
                                               $selected = " SELECTED";
                                               if ( $row['datepurchased'] == $datepurchased){
                                                           $selected = " SELECTED";
                                                           list($year, $month, $day) = explode("-", $datepurchased);
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$year.'</OPTION>'."\r\n";                                                                                                                                                                                 
                                            }
                                            ?>
                                        <option>2020</option>
                                        <option>2019</option>
                                        <option>2018</option>
                                        <option>2017</option>
                                        <option>2016</option>
                                        <option>2015</option>
                                        <option>2014</option>
                                        <option>2013</option>
                                        <option>2012</option>
                                        <option>2011</option>
                                        <option>2010</option>
                                        <option>2009</option>
                                        <option>2008</option>
                                        <option>2007</option>
                                        <option>2006</option>
                                        <option>2005</option>
                                        <option>2004</option>
                                        <option>2003</option>
                                        <option>2002</option>
                                        <option>2001</option>
                                        <option>2000</option>
                                        <option>1999</option>
                                        <option>1998</option>
                                        <option>1996</option>
                                        <option>1995</option>
                                        <option>1994</option>
                                        <option>1993</option>
                                        <option>1992</option>
                                        <option>1991</option>
                                        <option>1990</option>                                     
                                    </select>
                        </th>
                        <th><input type="submit" value="Update Lighting" name="light" />   </br></th>
                        </thead>
                            <tbody>
                                <tr>
                                    <td>Category:<select name="hardtype">
                                            <option value="" SELECTED></option>
                                            <?php 
                                            $cat = mysql_query("select id,hardware_type from l_hardware where user_id='".$_SESSION['uid']."' and id='".$_GET['id']."' order by hardware_type");
                                            while($row = mysql_fetch_array($cat)){
                                               $selected = " SELECTED";
                                               if ( $row['hardware_type'] == $hardware_type){
                                                           $selected = " SELECTED";
                                                        } else {
                                                           $selected = "";
                                                        }
                                                        echo '<OPTION value="'.$row['id'].'"'.$selected.'>'.$row['hardware_type'].'</OPTION>'."\r\n";
                                                     }
                                            ?>
                                            <option>Ballast</option>
                                            <option>Reflector</option>                                           
                                        </select></td>
                                    <td>Name:<input type="text" name="name" value="<? echo $lname?>" /></td>
                                    <td>Manufacturer:<input type="text" name="manufacturer" value="<? echo $hmanufacturer?>" /></td>                                                                    
                                </tr>
                                <tr>
                                    <td>Cost:<input type="text" name="cost" value="<?echo $cost?>" /></td>
                                    <td>Quantity:<input type="text" name="qty" value="<?echo $qty?>" /></td>
                                    <td>Notes:<textarea type="text" name="notes" rows="4" cols="20">
                                    
                                    <?=$notes?>
                                </textarea></td>
                                 
                            </tbody>
                        </table>                           
                    </form>
      </div>
		<div id="aside">
                    <h3>
                        Info:
                    </h3>
                    <p>Track your lighting to ensure healthy livestock.</p>
		</div>
		<div id="footer">
			Copyright © ReefersLog, 2012, wkoester All Rights Reserved
		</div>
	</div>
</div>
</html>
                